package cool.lichuan.framework.config.satoken;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author LiChuan
 * @date 2021/11/15 9:23
 */
@Configuration
@Slf4j
public class ResourcesConfig implements WebMvcConfigurer {
    /**
     * 默认首页的设置，当输入域名是可以自动跳转到默认指定的网页
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/view/index" );
    }

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaRouteInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/view/login", "/login","/yimiao/**", "/captcha",
                        // 静态资源
                        "/api/**", "/css/**", "/js/**", "/img/**", "/lib/**", "/pageVue/**", "/util/**", "/config.js");
    }
}
